package cn.wx.controller;

import cn.wx.UserFeignClient;
import cn.wx.domain.User;
import cn.wx.sentine.SentineFusing;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/get/{id}")
   // @SentinelResource(value="user-server-getById", fallback = "fuseDegradation")
    @SentinelResource(value="user-server-getById",  fallback = "fuseDegradation", fallbackClass = SentineFusing.class)
    public User getUser(@PathVariable Long id){
        return userFeignClient.getUser(id);
    }

    /*public User fuseDegradation(@PathVariable Long id,Throwable  e){
        return new User(-1L,"熔断了","拜拜");
    }*/
}
